<?php

namespace App\Http\Controllers;

use App\Models\Config;
use App\Http\Requests\StoreConfigRequest;
use App\Http\Requests\UpdateConfigRequest;

class ConfigController extends Controller {
    public function __construct() {
        $this->middleware(['auth:sanctum'])->only(['update']);
    }

    public function update(UpdateConfigRequest $request, $fieldName) {
        $config = Config::firstOrNew();
        $config[$fieldName] = $request->input() + $config[$fieldName] ?: [];
        $config->save();
        return $this->success('系统参数修改成功',$config[$fieldName]);
    }
    public function get_config($fieldName){
        $config = Config::firstOrNew();
        return $this->success(data:$config[$fieldName]);
    }


}
